//
// test.go
// Copyright (C) 2019 crane <crane@his-pc>
//
// Distributed under terms of the MIT license.
//

package main

import (
	"fmt"
)

func g_produce(os chan int, oe chan int) {
	for i := 0; i < 10; i++ {
		if i%2 == 0 {
			oe <- i
		} else {
			os <- i
		}
	}

	close(os)
	close(oe)
}

func g_consume(input chan int, output chan int) {
	s := 0
	for i := range input {
		s += i
	}

	output <- s
}

func main() {
	fmt.Println("start main")

	c_single := make(chan int, 10)
	c_even := make(chan int, 10)

	c_os := make(chan int, 1)
	c_oe := make(chan int, 1)

	go g_produce(c_single, c_even)
	go g_consume(c_single, c_os)
	go g_consume(c_even, c_oe)

	sum_s := <-c_os
	sum_e := <-c_oe

	fmt.Println(sum_s)
	fmt.Println(sum_e)
}
